package com.guigu.qingcheng.controller;


import com.guigu.qingcheng.domain.entity.PageResult;
import com.guigu.qingcheng.domain.pojo.TbAlbum;
import com.guigu.qingcheng.domain.pojo.TbBrand;
import com.guigu.qingcheng.service.TbAlbumService;
import com.guigu.qingcheng.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-05
 */
@RestController
@RequestMapping("/qingcheng/album")
@CrossOrigin
public class TbAlbumController {

    @Autowired
    private TbAlbumService albumService;

    // 分页条件查询
    @PostMapping("/findPage")
    public CommonResult findPage(@RequestBody Map<String, Object> searchMap, Integer page, Integer size) {
        return albumService.findPage(searchMap, page, size);
    }

    @PostMapping("/insert")
    public CommonResult insert(@RequestBody TbAlbum album) {
        boolean save = albumService.save(album);
        if (save){
            return CommonResult.ok();
        }
        return CommonResult.error();
    }

    @PostMapping("/update")
    public CommonResult update(@RequestBody TbAlbum album) {
        boolean update = albumService.updateById(album);
        if (update) {
            return CommonResult.ok();
        }
        return CommonResult.error();
    }

    @GetMapping("/delete")
    public CommonResult delete(Integer id) {
        boolean remove = albumService.removeById(id);
        if (remove){
            return CommonResult.ok();
        }
        return CommonResult.error();
    }

    @GetMapping("/findById")
    public CommonResult findById(Integer id) {
        TbAlbum album = albumService.getById(id);
        if (album==null){
            return CommonResult.error();
        }
        return CommonResult.ok().data("album",album);
    }
}

